package com.guigu.userservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.common.utils.R;
import com.guigu.userservice.dto.Equipment;
import com.guigu.userservice.entity.BusinessmanEquipment;
import com.guigu.userservice.feign.myEquipmentFeign;
import com.guigu.userservice.service.BusinessmanEquipmentService;
import com.guigu.userservice.vo.BusinessmanEquipmentVo;
import com.guigu.userservice.vo.EquipmentTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 业务员设备关联表  前端控制器
 * </p>
 *
 * @author zcy
 * @since 2025-10-17
 */
@RestController
@RequestMapping("/user/businessmanEquipment")
public class BusinessmanEquipmentController {
    @Autowired
    private BusinessmanEquipmentService BusinessmanEquipmentService;

    @Autowired
    private myEquipmentFeign myEquipmentFeign1;

    @PostMapping("saveBusinessmanEquipment")
    public R saveBusinessmanEquipment(@RequestBody BusinessmanEquipment businessmanEquipment)
        {
        return BusinessmanEquipmentService.saveBusinessmanEquipment(businessmanEquipment);
    }

    //分页查询业务员设备信息
    @PostMapping("/queryBusinessmanEquipment/{operatorId}/{pageNo}/{pageNum}")
    public List<Equipment> queryBusinessmanEquipment(@PathVariable("operatorId") Integer operatorId,
                                               @PathVariable("pageNo") Integer pageNo,
                                               @PathVariable("pageNum") Integer pageNum,
                                               @RequestBody BusinessmanEquipmentVo vo)
        {
        return BusinessmanEquipmentService.queryBusinessmanEquipment(operatorId,pageNo,pageNum,vo);
    }

    /**
     * 查询业务员归属设备
     */
    @PostMapping("/queryBusinessmanEquipment1/{operatorId}/{pageNo}/{pageNum}")
    public R queryBusinessmanEquipment1(@PathVariable("operatorId") Integer operatorId,
                                       @PathVariable("pageNo") Integer pageNo,
                                       @PathVariable("pageNum") Integer pageNum)
        {
        return BusinessmanEquipmentService.queryBusinessmanEquipment1(operatorId,pageNo,pageNum);
    }


    //查询业务员和哪台设备关联
    @GetMapping("/selectBusinessmanEquipmentList/{bid}")
    public List<BusinessmanEquipment> selectBusinessmanEquipmentList(@PathVariable("bid") Integer bid){
        QueryWrapper<BusinessmanEquipment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("businessman_id",bid);

        List<BusinessmanEquipment> list = BusinessmanEquipmentService.list(queryWrapper);
        for (BusinessmanEquipment bq:list
             ) {
            Equipment equipment = myEquipmentFeign1.selectEquipmentAndImageAndType2(Long.valueOf(bq.getEquipmentId()));
            bq.setEquipment(equipment);
        }

        return list;
    }

}
